<template>
  <view id="chooseSchool">
    <u-select
      v-model="show"
      :list="list"
      mode="single-column"
      title="请选择代取学校"

      :safe-area-inset-bottom="true"
      @confirm="confirm"
    ></u-select>
  </view>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      list: [
        {
          value: "1",
          label: "成都大学",
        },
        {
          value: "2",
          label: "成都理工大学",
        },
      ],
    };
  },
  methods: {
    //获取默认收货地址
    getDefaultAddress() {
      return new Promise((resolve) => {
        //跳转到填写订单页面之前 需要获取到用户的 默认收货地址
        this.$u.api.getDefaultAddressUrlApi().then((res) => {
          this.$u.vuex("vuex_chooseAddress", res.elifeAddress);
          resolve();
        });
      });
    },
    //获取学校的banner 信息
    getBannerInfo(schoolId) {
      return new Promise((resolve) => {
        //跳转到填写订单页面之前 需要获取到用户的 公告
        this.$u.api.getAllBannerApi({ schoolId: schoolId }).then((res) => {
          this.$u.vuex("vuex_Banner", res.elifeBannerList);
          resolve();
        });
      });
    },
    // 获取 快递 价格 根据不同的学校
    getBoxPrice(schoolId) {
      return new Promise((resolve) => {
        this.$u.api.getAllPriceApi({ schoolId: schoolId }).then((res) => {
          this.$u.vuex("vuex_priceList", res.priceList);
          resolve();
        });
      });
    },
    // 获取 快递list  根据不同的学校
    getKuaidiList(schoolId) {
      return new Promise((resolve) => {
        this.$u.api.getKuaidiBySchoolApi({ schoolId: schoolId }).then((res) => {
          this.$u.vuex("vuex_kuaidiList", res.kuaidiList);
          resolve();
        });
      });
    },
    // e label 学校名称  value 学校id
    confirm(e) {
      // console.log(e[0].value);
      var schoolId = parseInt(e[0].value)
      this.getDefaultAddress()
        .then(() => {
          return this.getBannerInfo(schoolId);
        })
        .then(() => {
          return this.getBoxPrice(schoolId);
        })
        .then(() => {
          return this.getKuaidiList(schoolId);
        })
        .then(() => {
          this.$u.route({
            url: "pages/takeBox/takeBox",
            params: e[0]
          });
        });
    },
  },
  //请求数据
  created() {},
};
</script>

<style lang ='less' >
#chooseSchool {
  .u-select__header {
    background-color: #666666 !important;
  }
}
</style>
